/* v4 7.5.2018 */
//=================================================
/**
* This function is called when the user clicks on the anchor labeled "Aufklappen"
* in the header of the particular year with all race results.
* After having clicked the link, an AJAX call is executed to load the page with
* the requested race results of the according year. To achieve this goal the
* page must contain a certain structure:
*
... ...
*
*
* The clicked link "Aufklappen" must be embedded in a
element that is emediatly
* followed by an element whoose id contains the link to the target html
* page that contains all race results of the according year in several
* elements. After having loaded the target page, each
*/
function scanTargetResultPageAndBuildLinkList(anchorElement) {
// slide down (open) the list with all races of the reagrded year
$(anchorElement).parent("div").next("article").slideToggle("fast");
if ($(anchorElement).text() == "Aufklappen") {
$(anchorElement).text("Zuklappen");
// select immediatly after current and do not display the
// horizontal row since the list gets a border.
var hrElement = "hr" + $(anchorElement).attr("href").substring(1);
$('#' + hrElement).addClass("suppress");
// Check whether target page was already loaded and abort if neccessary
if ($(anchorElement).parent("div").next("article").find("ul").length) {
// target page already loaded, no need to makae AJAX call again!
return;
}
// article id's value contains the target html page name
var targetPage = $(anchorElement).parent("div").next("article").attr("id");
// list element where each results is added as
element
var ulElement = $('
');
var $div = $('
'); // temp dummy element to load ajax call content into
// load the content of the target page into the dummy
element
$div.load(targetPage, function(){
// now $(this) contains the loaded html page content
// the target page contains each race result within an element
var targetArticleIds = $(this).find("article").map(function() {
// this callback function will be called once for each matching element
return $(this).attr("id");
});
// get all meeting names from target table, located in
//
of table
var meetingNames = $(this).find("td.meetingName").map(function() {
// this callback function will be called once for each matching element
var strWithoutWhitespaces = $(this).text().replace(/\s+/g, ' ');
return strWithoutWhitespaces.trim();
});
// get all meeting dates from target table, located in
//
of table
var meetingDates = $(this).find("td.meetingDate").map(function() {
// this callback function will be called once for each matching element
var strWithoutWhitespaces = $(this).text().replace(/\s+/g, ' ');
return strWithoutWhitespaces.trim();
});
// get all alternate meeting dates from target table, located in "title"
// attribute of
var alternateMeetingDates = $(this).find("br#alternateMeetingDate").map(function() {
// this callback function will be called once for each matching element
var strWithoutWhitespaces = $(this).attr("title").replace(/\s+/g, ' ');
return strWithoutWhitespaces.trim();
});
// parse and extract meeting date and city from
"10.1. - 12.1.2018 in Frankfurt"
for (var i = 0; i < targetArticleIds.length; i++) {
// first take alternate value for meeting date and city from
///
var md = alternateMeetingDates[i];
// if alternate value is empty then take original value
if (md.trim().length == 0) {
var start = meetingDates[i].indexOf(" ")+1;
var end = meetingDates[i].indexOf(",")
var m = meetingDates[i].substring(start, end);
end = m.lastIndexOf(".") + 1;
md = m.substring(0, end);
start = m.lastIndexOf(" in");
md = md + m.substring(start);
}
// append race result table link
//ulElement.append("